package com.chen.servlet;/*
package com.chen.servlet;

import com.chen.service.FlightService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/deleteFlight")
public class DeleteFlightServlet extends HttpServlet {
    private FlightService flightService = new FlightService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        String phone = req.getParameter("phone");
        //根据主键id删除信息
        //1、获取id
        String idStr = req.getParameter("id");
        if(idStr == null || idStr == ""){
            //跳转到错误页面，客户端传递有误
            req.setAttribute("errorMsg", "id的值为空");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
            return;
        }
        try {
            Integer id = Integer.parseInt(idStr);
            //int result = flightService.deleteFlightById(id);
            int result = flightService.updateDeleteById(id);
            if(result > 0){
                //如果删除成功，则跳转(转发)到 /showFlight 页面
                req.setAttribute("phone", phone);
                req.getRequestDispatcher("showFlight").forward(req, resp);
            }else{
                //如果删除失败，则跳转(转发)到 error.jsp 页面
                req.setAttribute("errorMsg", "删除失败");
                req.getRequestDispatcher("error.jsp").forward(req, resp);
            }
        }catch (NumberFormatException e){
            //该异常为类型转换错误
            e.printStackTrace();
            req.setAttribute("errorMsg", "类型装换异常，id的值不能装换位Integer");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        } catch (Exception e){
            e.printStackTrace();
            req.setAttribute("errorMsg", "系统异常");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        }
    }
}
*/
